/*
*
* Copyright (C) 2004 - 2008 BitLaboratory (see http://www.bitlaboratory.com)
* All rights reserved. 
*
* Redistribution and use in source and binary forms, with or without modification, 
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
*    this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
*    this list of conditions and the following disclaimer in the documentation
*    and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
*    derived from this software without specific prior written permission. 
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
* OF SUCH DAMAGE.
*
* You can find the latest version of this library at http://www.bitlaboratory.com
*
*/


using System;
using System.Text;
using BitLaboratory.Win32Api;
using System.Runtime.InteropServices;

namespace BitLaboratory.Win32Api.Windows
{

#if( _SHARED_ )
	internal delegate bool WNDENUMPROC(IntPtr hWnd, IntPtr lParam);
	internal delegate int WNDPROC(IntPtr hWnd, int uMessage, IntPtr wPraram, IntPtr lParam);
#else
	public delegate bool WNDENUMPROC(IntPtr hWnd, IntPtr lParam);
	public delegate int WNDPROC(IntPtr hWnd, int uMessage, IntPtr wPraram, IntPtr lParam);
#endif

#if( _SHARED_ )
	internal class APIWindow
#else
	public class APIWindow
#endif
	{
		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern IntPtr GetActiveWindow( );
		
		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool AdjustWindowRect(ref RECT lpRect, uint dwStyle, bool bMenu);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool AdjustWindowRectEx(ref RECT lpRect, uint dwStyle, bool bMenu, uint dwExStyle);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool AllowSetForegroundWindow(uint dwProcessId);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern uint ArrangeIconicWindows(IntPtr hWnd);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool BringWindowToTop(IntPtr hWnd);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern int CascadeWindows(IntPtr hwndParent, CascadeFlags wHow, ref RECT lpRect, uint cKids, ref IntPtr lpKids);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern IntPtr ChildWindowFromPoint(IntPtr hWndParent, POINT Point);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern IntPtr ChildWindowFromPointEx(IntPtr hwndParent, POINT pt, ChildWindowFromPointFlags uFlags);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern IntPtr WindowFromPoint( POINT Point );

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		//public static extern IntPtr CreateWindow(String lpClassName, String lpWindowName, WindowStyles dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, [ MarshalAs( UnmanagedType.AsAny )] object lpParam);
		public static extern IntPtr CreateWindow(string lpClassName, string lpWindowName, uint dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, object lpParam);

		//public static extern IntPtr CreateWindowEx(int dwExStyle, string lpszClassName, string lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, object lpParam);
		//[DllImport("User32.dll", CharSet=CharSet.Auto)]
		[DllImport("User32.dll")]
		public static extern IntPtr CreateWindowEx(uint dwExStyle, string lpClassName, string lpWindowName, uint dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam /*ref object lpParam*/);


		[DllImport("User32.dll", CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
		public static extern bool EnumChildProc(IntPtr hWnd, IntPtr lParam);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern IntPtr EnumClaw(IntPtr hwndParent);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool EnumThreadWindows(uint dwThreadId, WNDENUMPROC lpfn, IntPtr lParam);

		[DllImport("User32.dll", CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
		public static extern bool EnumThreadWndProc(IntPtr hwnd, IntPtr lParam);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool EnumWindows( WNDENUMPROC lpEnumFunc, IntPtr lParam);

		[DllImport("User32.dll", CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
		public static extern bool EnumWindowsProc(IntPtr hwnd, IntPtr lParam);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern IntPtr FindWindow( String lpClassName, String lpWindowName );

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool GetAltTabInfo(IntPtr hwnd, int iItem, ref ALTTABINFO pati, String pszItemText, uint cchItemText);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern IntPtr GetAncestor(IntPtr hwnd, AncestorFlags gaFlags);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool GetClientRect(IntPtr hWnd, ref RECT lpRect);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern IntPtr GetDesktopWindow();

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern IntPtr GetForegroundWindow();

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool GetGUIThreadInfo(uint idThread, ref GUITHREADINFO lpgui);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern IntPtr GetLastActivePopup(IntPtr hWnd);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool GetLayeredWindowAttributes(IntPtr hwnd, ref ulong pcrKey, ref byte pbAlpha, ref LayeredWindowAttributesFlags pdwFlags);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern uint GetLayout(IntPtr hdc);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern IntPtr GetNextWindow(IntPtr hWnd, NextWindowFlag wCmd);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern IntPtr GetParent(IntPtr hWnd);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool GetProcessDefaultLayout(ref uint pdwDefaultLayout);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool GetTitleBarInfo(IntPtr hwnd, ref TITLEBARINFO pti);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern IntPtr GetTopWindow(IntPtr hWnd);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern IntPtr GetWindow(IntPtr hWnd, WindowCmdFlags uCmd);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool GetWindowInfo(IntPtr hwnd, ref WINDOWINFO pwi);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern uint GetWindowModuleFileName(IntPtr hwnd, String lpszFileName, uint cchFileNameMax);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern int GetWindowText(IntPtr hWnd, String lpString, int nMaxCount);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern int GetWindowTextLength(IntPtr hWnd);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern uint GetWindowThreadProcessId(IntPtr hWnd, ref uint lpdwProcessId);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool IsChild(IntPtr hWndParent, IntPtr hWnd);

		[DllImport("User32.dll", CharSet=CharSet.Auto, CallingConvention=CallingConvention.Cdecl)]
		public static extern bool IsGUIThread(bool bConvert);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool IsIconic(IntPtr hWnd);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool IsWindow(IntPtr hWnd);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool IsWindowUnicode(IntPtr hWnd);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool IsWindowVisible(IntPtr hWnd);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool IsZoomed(IntPtr hWnd);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool LockSetForegroundWindow(LockSetForegroundWindowFlags uLockCode);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool OpenIcon(IntPtr hWnd);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern IntPtr RealChildWindowFromPoint(IntPtr hwndParent, POINT ptParentClientCoords);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern uint RealGetWindowClass(IntPtr  hwnd, StringBuilder pszType, uint  cchType);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool SetForegroundWindow(IntPtr hWnd);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool SetLayeredWindowAttributes(IntPtr hwnd, ulong crKey, byte bAlpha, LayeredWindowAttributesFlags dwFlags);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern int ShowWindow(IntPtr hWnd, short cmdShow);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool AnimateWindow(IntPtr hWnd, uint dwTime, AnimateWindowFlags dwFlags);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern long BeginDeferWindowPos (int nNumWindows);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern long CloseWindow(IntPtr hWnd);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern IntPtr DeferWindowPos(IntPtr hWinPosInfo, IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool DestroyWindow(IntPtr hWnd);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern long EnableWindow(IntPtr hWnd, long fEnable);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool EndDeferWindowPos(IntPtr hWinPosInfo);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool EnumChildWindows(IntPtr hWndParent, WNDENUMPROC lpEnumFunc, IntPtr lParam);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern long FlashWindow(IntPtr hWnd, bool bInvert);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, WindowPosFlags flags);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool SetWindowPos(IntPtr hWnd, WindowPosHWNDFlags hWndInsertAfter, int x, int y, int cx, int cy, WindowPosFlags flags);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern bool UpdateWindow(IntPtr hWnd);

		//[DllImport("User32.dll", CharSet=CharSet.Auto)]
		[DllImport("User32.dll")]
		public static extern IntPtr RegisterClass( ref WNDCLASS wc );

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern IntPtr RegisterClassEx(ref WNDCLASSEX wc);

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern int DefWindowProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
	
		[DllImport("User32.dll", CharSet = CharSet.Auto)]
		public static extern int ShowWindow(IntPtr hWnd, ShowWindowStyles cmdShow);

		[DllImport("User32.dll", CharSet = CharSet.Auto)]
		public static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref POINT pptDst, ref SIZE psize, IntPtr hdcSrc, ref POINT pprSrc, int crKey, ref BLENDFUNCTION pblend, int dwFlags);

		[DllImport("User32.dll", CharSet = CharSet.Auto)]
		public static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref POINT pptDst, ref SIZE psize, IntPtr hdcSrc, ref POINT pprSrc, int crKey, ref BLENDFUNCTION pblend, UpdateLayeredWindowFlags flags);
		

		[DllImport("User32.dll", CharSet=CharSet.Auto)]
		public static extern IntPtr SetWindowLong(IntPtr hWnd, WindowLongIndexFlags nIndex, int dwNewLong);

		[DllImport("user32.dll", CharSet=CharSet.Auto)]
		public static extern IntPtr SetWindowLong(IntPtr hWnd, WindowLongIndexFlags nIndex, IntPtr dwNewLong);
 
		[DllImport("user32.dll", CharSet=CharSet.Auto)]
		public static extern IntPtr SetWindowLong(IntPtr hWnd, WindowLongIndexFlags nIndex, WNDPROC dwNewLong);

		[DllImport("user32.dll", CharSet=CharSet.Auto)]
		public static extern IntPtr GetWindowLong(IntPtr hWnd, WindowLongIndexFlags nIndex);
 
		[DllImport("user32.dll", CharSet=CharSet.Auto)]
		public static extern bool GetClassInfo(IntPtr hInst, string lpszClass, [In, Out] WNDCLASS lpWndClass);
 
		[DllImport("user32.dll", CharSet=CharSet.Auto)]
		public static extern bool GetClassInfo(IntPtr hInst, string lpszClass, IntPtr lpWndClass);
 
		[DllImport("user32.dll", CharSet=CharSet.Auto)]
		public static extern bool UnregisterClass( string lpClassName, IntPtr hInstance );
	}
}
